import http.client
import json

import requests
import init_env_impl


# from langchain_anthropic import ChatAnthropic
from langchain.chat_models import init_chat_model
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain.tools import Tool
from langchain_core.messages import HumanMessage
from langgraph.checkpoint.memory import MemorySaver
from langgraph.prebuilt import create_react_agent


def test_google_search(query):
    url = "https://google.serper.dev/search"
    payload = json.dumps({
        "q": query
    })
    headers = {
        'X-API-KEY': init_env_impl.get_evn_key("GOOGLE_API_KEY"),
        'Content-Type': init_env_impl.get_evn_key("GOOGLE_API_RES_TYPE")
    }
    response = requests.request("POST", url, headers=headers, data=payload)
    print(response.text)

def test_agent_2_agent():
    memory = MemorySaver()
    model = init_chat_model(model_name="deepseek-chat")
    search = TavilySearchResults(max_results=5)
    tools = [search]
    agent_executor = create_react_agent(model, tools, checkpointer=memory)
    config = {"configurable": {"thread_id": "abc123"}}
    for step in agent_executor.stream(
        {"messages": [HumanMessage(content="hi im bob! and i live in sf")]},
        config,
        stream_mode="values",
    ):
        step["messages"][-1].pretty_print()





if __name__ == "__main__":
    test_google_search("纽约好吃的汉堡店有哪些")
    
